package org.smart4j.plugin.security.realm;

import org.apache.shiro.realm.jdbc.JdbcRealm;
import org.smart4j.framework.helper.DatabaseHelper;
import org.smart4j.plugin.security.SecurityConfig;
import org.smart4j.plugin.security.password.Md5CredentialsMatcher;

import javax.sql.DataSource;

/**
 * Created by Wangminze on 2016/12/31.
 * Description: 基于Smart 的 JDBC Realm （需要提供smart.plugin.security.jdbc.* 配置项）
 */
public class SmartJdbcRealm extends JdbcRealm {

    public SmartJdbcRealm(){
        super.setDataSource((DatabaseHelper.getDataSource()));
        super.setAuthenticationQuery(SecurityConfig.getJdbcAuthcQuery());
        super.setUserRolesQuery(SecurityConfig.getJdbcRolesQuery());
        super.setPermissionsQuery(SecurityConfig.getJdbcPermissionsQuery());
        super.setPermissionsLookupEnabled(true);
        //使用MD5加密算法
        super.setCredentialsMatcher(new Md5CredentialsMatcher());
    }
}
